$(function () {
  //首页的轮播
  if ($(".swiper_lunbox .swiper-container .swiper-slide").size() >= 1) {
    var swiper = new Swiper(".swiper_lunbox .swiper-container", {
      lazy: true,
      speed: 400,
      autoplay: {
        delay: 5000,
        disableOnInteraction: false,
      },
      pagination: {
        el: ".swiper_lunbox .swiper-pagination",
        clickable: true,
      },
    });
  }

  // 切换公共
  $(".switchbox  .switchlab  .a").click(function () {
    $(this).addClass("on").siblings().removeClass("on");
    $(this).parents(".switchbox").find(".switchitem .item_").eq($(this).index()).show().siblings().hide();
    $(this).parents(".switchbox").find(".switchmore a").eq($(this).index()).show().siblings().hide();
    $(window).trigger("scroll");
  });
  //meun
  $(".header_top .numbox,.clode_burger").click(function () {
    $(".header_top .numbox").toggleClass("on");
    $(".burger").slideToggle();
    $(".content").toggleClass("noscroll");
  });
  // UP回到顶部
  $(window).scroll(function () {
    var scroll_len = $(window).scrollTop();
    if (scroll_len > 120) {
      $(".QZ-up").fadeIn();
    } else {
      $(".QZ-up").fadeOut();
    }
  });
  $(".QZ-up").click(function () {
    $("body,html").animate({ scrollTop: 0 }, 300);
  });

  //导航头部
  if ($(".swiper_nav .swiper-container .swiper-slide").size() >= 1) {
    var side = "auto";
    var swiper_nav = new Swiper(".swiper_nav .swiper-container", {
      slidesPerView: side,
    });
    $(".swiper_nav .swiper-container .swiper-slide").each(function (index) {
      if ($(this).hasClass("on") && index > 5) {
        var index_ = $(this).index();
        swiper_nav.slideTo(index_, false); //切换到第一个slide，速度为1秒;
      }
    });
  }

  $(window).load(function () {
    //切换
    function switch_tab(a, b) {
      a.click(function () {
        $(this).addClass("on").siblings().removeClass("on");
        b.eq($(this).index()).show().siblings().hide();
      });
    }

    //PAGE分页
    $(".page>span .cbtn").css("display", "none");
    $(".page>span").click(function () {
      $(this).children("div").show();
    });
    $(document).click(function () {
      $(".page>span .cbtn").css("display", "none");
    });
    $(".page>span .cbtn,.page>span").click(function (event) {
      event.stopPropagation();
    });
  });
});
//video
$(function () {
  var wind_w = $(window).width();
  if (wind_w <= 768) {
    $(".detaile_cont  p iframe").css("height", wind_w * 0.6);
  }
});

// 加载更多;
function loadmore(index_) {
  var arr = [];
  $(".loadmore").each(function (i) {
    arr.push(0);
    var that = $(this);
    var size = that.find(".list ul li").size();
    that.find(".list ul li").each(function (index) {
      if (index >= index_) {
        $(this).hide();
      } else {
        $(this).show();
      }
    });
    if (size <= index_) {
      that.find(".morebtn").hide();
    } else {
      that.find(".morebtn").click(function () {
        arr[i]++;
        var length = index_ + index_ * arr[i];
        that.find(".list ul li:lt(" + length + ")").show();
        if (length >= size) {
          that.find(".morebtn").hide();
        }
      });
    }
  });
}

var bgTH = $(".header_top").height();

isIE6 = function () {
  return !!window.ActiveXObject && !window.XMLHttpRequest;
}; //判断IE6;
function scroll_ad() {
  var wt = $(window).scrollTop();
  t = wt >= bgTH ? (isIE6() == true ? wt : 0) : bgTH - wt;
  $(".swiper_nav .flexd").css({ top: t + "px" });
  // ---------------------------
  //加载内容
  if ($("#morelink").size() >= 1) {
    var morelink = $("#morelink").offset().top;
    if (wt >= morelink - $(window).height()) {
      addli();
    }
  }

  // -------------------------
}

var html = $(".newslist ul:first").html();
var start = true;

function addli() {
  if (!start) {
    return;
  }
  start = false;
  var word = $(".swiper-wrapper div.on").attr("word");
  var url = "/api/am_get_article";
  var data = { word: word, page: page };
  $.post(
    url,
    data,
    function (res) {
      if (res.code == 1) {
        var li = "";
        res.data.article.forEach(function (v, i) {
          li += '                    <li class="li1">\n' + '                        <a href="/news/' + v["id"] + '.html" target="_blank" class="box_flex">\n' + '                            <div class="infor box_flex_1">\n' + '                                <div class="name">' + v["title"] + "</div>\n" + '                                <div class="p"><span>' + v["hour"] + "</span><span>" + "" + "</span>\n" + "                                </div>\n" + "                            </div>\n" + '                            <div class="img">\n' + '                                <img src="' + v["litpic"] + '" alt="' + v["title"] + '">\n' + "                            </div>\n" + "                        </a>\n" + "                    </li>";
        });
        $(".newslist ul:first").append(li);
        page = res.data["page"];
        start = true;
      } else {
        console.log("暂无数据");
      }
      if ($(".newslist ul:first").text() == "") {
        $(".newslist ul:first").append("<p style='text-align:center'>暂无数据<p>");
      }
    },
    "json"
  );
}

scroll_ad();
$(window).scroll(function () {
  scroll_ad();
});

//列表页面查看更多
if ($(".Min1").hasClass("switchitem")) {
  if ($(".Min1 li").size() > 8) {
    $(".Min1 ul li:gt(" + 7 + ")").hide();
    $(".Min1 .more_a").show();
    $(".Min1 .more_a").click(function () {
      $(".Min1 ul li").show();
      $(this).hide();
    });
  }
}
// 底部的轮播
$(window).load(function () {
  if ($(".Min3 .swiper-slide").size() >= 1) {
    var w = $(" .Min3 .swiper-slide").eq(0).find("img").width();
    var h = $(" .Min3 .swiper-slide").eq(0).find("img").height();
    if (w > h) {
      $(" .Min3 .swiper-slide .img").addClass("img2");
    }
    var swiperlunbox = new Swiper(" .Min3 .swiper-container", {
      effect: "coverflow",
      grabCursor: true,
      navigation: {
        nextEl: ".Min3 .swipernext",
        prevEl: ".Min3 .swiperprev",
      },
      initialSlide: 1,
      loop: true,
      slidesPerView: "auto",
      observer: true,
      observeParents: true,
      centeredSlides: true,
      // autoplay: true,
      coverflowEffect: {
        rotate: 0,
        stretch: "0%",
        depth: 200,
        modifier: 1,
        slideShadows: false,
      },
    });
  }
});
// 首页的精选推荐
if ($(".Min9 .swiper-slide").size() >= 1) {
  var swiper = new Swiper(".Min9 .swiper-container", {
    lazy: {
      loadPrevNext: true,
      loadPrevNextAmount: 6,
    },
    slidesPerView: "auto",
    scrollbar: {
      el: ".Min9  .swiper-scrollbar",
      //   hide: true,
    },
  });
}
// 首页的最新更新

if ($(".swiper_switch .swiper-slide").size() >= 1) {
  var gallerytab = new Swiper(".swiper_switch .swiper-container", {
    slidesPerView: 4,
    freeMode: true,
    watchSlidesVisibility: true,
    watchSlidesProgress: true,
  });
}

// 首页排行榜
if ($(".Min10").size() >= 1) {
  if ($(".Min10 .swiper_switch .swiper-slide").size() >= 1) {
    var gallerytab = new Swiper(".swiper_switch .swiper-container", {
      slidesPerView: 4,
      freeMode: true,
      watchSlidesVisibility: true,
      watchSlidesProgress: true,
    });
  }
  if ($(".Min10 .swiper_item .swiper-slide").size() >= 1) {
    var galleryitem = new Swiper(".Min10 .swiper_item .swiper-container", {
      spaceBetween: 10,
      lazy: {
        loadPrevNext: true,
        loadPrevNextAmount: 6,
      },
      thumbs: {
        swiper: gallerytab,
      },
    });
  }
}

// 首页排行榜
if ($(".Min2-swiper").size() >= 1) {
  console.log("asas");
  var galleryitem2 = new Swiper(".Min2-swiper .swiper_item .swiper-container", {
    spaceBetween: 10,
    lazy: {
      loadPrevNext: true,
      loadPrevNextAmount: 6,
    },
    on: {
      slideChangeTransitionStart: function () {
        console.log(this.activeIndex);
        $(".Min2-swiper .swiperswitch .swiper-slide").eq(this.activeIndex).addClass("active-nav").siblings().removeClass("active-nav");
      },
    },
  });

  var gallerytab2 = new Swiper(".Min2-swiper .swiperswitch .swiper-container", {
    slidesPerView: "auto",
  });
  $(".Min2-swiper .swiperswitch .swiper-slide").click(function () {
    var i = $(this).index();
    console.log(i);
    galleryitem2.slideTo(i);
  });
}
